﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace xyw
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            XYW.BLL.News bllNews = new XYW.BLL.News();
            XYW.BLL.News_Classify bllNewsClassify = new XYW.BLL.News_Classify();
            DataTable dt = bllNewsClassify.GetList("type=0").Tables[0];

            this.RepeaterClassify.DataSource = dt;
            this.RepeaterClassify.DataBind();
            this.RepeaterNews.DataSource = dt;
            this.RepeaterNews.DataBind();

            foreach (RepeaterItem ri in RepeaterNews.Items)
            {
                string classify = (ri.FindControl("hd_Classify") as HiddenField).Value;
                Repeater NewsList = (ri.FindControl("Repeater1") as Repeater);
                NewsList.DataSource = bllNews.GetListByPage(" sortBy=1 and classify='" + classify + "'", "id desc", 0, 5);
                NewsList.DataBind();
                HyperLink linkTop1 = ((ri.FindControl("hl_Top1")) as HyperLink);
                List<XYW.Model.News> modelNews = bllNews.GetModelList(" sortBy=2 and classify='" + classify + "'");
                if (modelNews.Count>0)
                {
                    linkTop1.Text = modelNews[0].title;
                    linkTop1.NavigateUrl = "./NewsPage.aspx?id=" + modelNews[0].ID.ToString();
                }
            }

            this.RepeaterFen.DataSource = bllNews.GetListByPage(" sortBy=1 and classify in(select classifyName from News_Classify where type=1)", "id desc", 0, 5);
            this.RepeaterFen.DataBind();
        }
    }
}